import java.util.Arrays;

public class Test {

    public static void oddNumbersPrecedeEvenNumbers(int[] arr){
        //1.创建两个数组分别存放奇数和偶数
        int[] oddNumber = new int[arr.length];
        int[] evenNumber = new int[arr.length];
        //2.找到奇数和偶数放进分别放进奇数数组和偶数数组里
        int indexOddNumber = 0;
        int indexEvenNumber = 0;
        int i = 0;
        for (i = 0; i < arr.length; i++){
            if ((arr[i] % 2) == 1){
                oddNumber[indexOddNumber] = arr[i];
                indexOddNumber++;
            }else{
                evenNumber[indexEvenNumber] = arr[i];
                indexEvenNumber++;
            }
        }
        //3.先存放奇数在存放偶数
        for (i = 0; i < indexOddNumber; i++){
            arr[i] = oddNumber[i];
        }
        int j = 0;
        //4.再存放偶数
        for (i = indexOddNumber; i < arr.length; i++){
            arr[i] = evenNumber[j];
            j++;
        }
    }
    public static void main(String[] args) {
        //奇数位于偶数之前
        int[] arr1 = new int[]{1,7,5,9,4,6,4,1,2,3,4};
        oddNumbersPrecedeEvenNumbers(arr1);
        System.out.println(Arrays.toString(arr1));
    }
}
